<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="text" name="username" id="username"/>
    <input type="text" name="age" id="age"/>
    <button id="btn">添加</button>
</body>
<script>
    var userName = document.getElementById("username");
    var age = document.getElementById("age");
    var btn = document.getElementById("btn");
    btn.onclick = function(){
        userName = userName.value;
        age = age.value;
        var formData = new FormData();
        formData.append("username",userName);
        formData.append("age",age);
        fetch("http://localhost:8000/",{
            method:"POST",
            body:formData
        }).then(res=>{
            return res.text();
        }).then(res=>{
            console.log(res);
        })
    }
</script>
</html>